/*
-------------------------------------------------------------------
BIE is Copyright 2001-2004 Brunswick Corp.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/bie_license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------

*/
package tests.prefs;

import java.util.prefs.*;
import java.io.*;

public class PreferenceGenerator_1 {
    public static boolean contains(Preferences node, String key) {
        return node.get(key, null) != null;
    }

    public static String containsValue(Preferences node, String value) {
        try {
            // Get all the keys
            String[] keys = node.keys();
    
            // Scan the keys
            for (int i=0; i<keys.length; i++) {
                if (value.equals(node.get(keys[i], null))) {
                    return keys[i];
                }
            }
        } catch (BackingStoreException e) {
        }
        return null;
    }
    

   public static void main(String[] args) throws Exception{
        
       
        //set route info
        Preferences prefs = Preferences.systemRoot().node("/xbotts");        
        
        //set up xbotts node
        prefs.put("comment","This is the system root");
        prefs.put("company","Webden Interactive");
        prefs.put("destination","localhost");
        prefs.put("key","system");
        prefs.put("outboundRouteKey","system");
        prefs.putInt("maxThreads",10);
        prefs.putBoolean("runGC",false);
        prefs.putInt("shutdownThreadWait",20);
        
        //set notification info
        prefs = Preferences.systemRoot().node("/xbotts/notification");
        
        prefs.put("criticalErrorMailToList","");
        prefs.put("errorMailToList","");
        prefs.put("inboundTransactionMailToList","");
        prefs.put("outboundTransactionMailToList","");
        prefs.put("translationErrorMailToList","");
        
        prefs.putBoolean("mailOnCriticalError",false);
        prefs.putBoolean("mailOnError",false);
        prefs.putBoolean("mailOnInboundTransaction",false);
        prefs.putBoolean("mailOnOutboundTransaction",false);
        prefs.putBoolean("mailOnTranslationError",false);
        prefs.put("mailServer","");
        prefs.put("smtpServer","");
        
        //set Translation info
        prefs = Preferences.systemRoot().node("/xbotts/Translation");

        prefs.put("inboundMessageMap","CustomMaps.GeneralTransfer");
        prefs.put("inboundResponseMessageMap","CustomMaps.GeneralTransfer");
        prefs.put("inboundUO","com.webdeninteractive.xbotts.universalobject.utility.General");
        prefs.put("outboundMessageMap","CustomMaps.GeneralTransfer");
        prefs.put("outboundResponseMessageMap","CustomMaps.GeneralTransfer");
        prefs.put("outboundUO","com.webdeninteractive.xbotts.universalobject.utility.General");
        
        //set File System info
        prefs = Preferences.systemRoot().node("/xbotts/FileSystem");
        
        prefs.put("inboundAtticDirectory","/cabinet/attic/inbound");
        prefs.put("inboundErrorDirectory","/cabinet/error/inbound");
        prefs.put("inboundTempDirectory","/cabinet/temp/inbound");
        prefs.put("outboundAtticDirectory","/cabinet/attic/outbound");
        prefs.put("outboundErrorDirectory","/cabinet/error/outbound");
        prefs.put("outboundTempDirectory","/cabinet/temp/outbound");
        prefs.put("logDirectory","/logs");
        prefs.put("logPriority","INFO");
        
        //set File System info
        prefs = Preferences.systemRoot().node("/xbotts/Services");
        
        prefs.put("fileSystemClientClass","");
        prefs.put("ftpClientClass","com.webdeninteractive.xbotts.client.serviceproviders.FTPServiceClient");
        prefs.put("webServiceClientClass","com.webdeninteractive.xbotts.client.serviceproviders.WebServiceClient");
               
        prefs = Preferences.systemRoot().node("/xbotts");
           
        try {
            // Export the node to a file
            prefs.exportSubtree(new FileOutputStream("z:/xbottsDEV/xbottsDEV/conf/System.xml"));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (BackingStoreException e) {
            e.printStackTrace();
        }
        System.out.println("done");
   }
}

